package se.topshelf.golftracker.core.domain;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 *
 */
@Entity
@Table(name = "Club")
public class Club extends BaseEntity implements Comparable<Club>{
    @NotNull
    @ManyToOne
    @JoinColumn(name = "clubModelId")
    private ClubModel clubModel;

    @NotNull
    @Enumerated(EnumType.STRING)
    private ClubType clubType;

    public Club() {
    }

    public Club(ClubModel clubModel, ClubType clubType) {
        this.clubModel = clubModel;
        this.clubType = clubType;
    }

    public ClubModel getClubModel() {
        return clubModel;
    }

    public void setClubModel(ClubModel clubModel) {
        this.clubModel = clubModel;
    }

    public ClubType getClubType() {
        return clubType;
    }

    public void setClubType(ClubType clubType) {
        this.clubType = clubType;
    }

    public int compareTo(Club o) {
        int clubModelCompare = clubModel.compareTo(o.getClubModel());
        if(clubModelCompare == 0){
            return clubType.compareTo(o.getClubType());
        }
        return clubModelCompare;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Club club = (Club) o;

        if (!clubModel.equals(club.clubModel)) return false;
        if (clubType != club.clubType) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = clubModel.hashCode();
        result = 31 * result + clubType.hashCode();
        return result;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("Club");
        sb.append("{clubModel=").append(clubModel);
        sb.append(", clubType=").append(clubType);
        sb.append('}');
        return sb.toString();
    }
}
